//
//  UsedCarDetailViewController.m
//  WWXELuShang
//
//  Created by 王涛 on 15/12/18.
//  Copyright © 2015年 lanou. All rights reserved.
//

#import "UsedCarDetailViewController.h"
#import "UsedCarDetail.h"
#import "UsedCarDetailView.h"
#import "CarIconScrollView.h"
@interface UsedCarDetailViewController ()
@property (nonatomic, strong) UsedCarDetail *usedCarDetail;
@property (nonatomic, strong) UsedCarDetailView *usedDetailView;
@property (nonatomic, strong) CarIconScrollView *carIconScrollView;
@property (nonatomic, strong) UIScrollView *mainScrollView;
@property (nonatomic, strong) UIActivityIndicatorView *activityView;
@end

@implementation UsedCarDetailViewController
- (UIActivityIndicatorView *)activityView {
    if (!_activityView) {
        _activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:(UIActivityIndicatorViewStyleWhiteLarge)];
        _activityView.center = CGPointMake(kWidth / 2, kHeight / 2 - 55);
        [self.view addSubview:_activityView];
    }
    return _activityView;
}
//解析二手车详情
- (void)jsonUsedCarDetail {
    [LORequestManger GET:[NSString stringWithFormat:kUsedCarDetail,self.ID] success:^(id response) {
        NSDictionary *dic = (NSDictionary *)response;
        self.usedCarDetail = [UsedCarDetail setValuesWithDictionary:dic[@"result"]];
        self.title = self.usedCarDetail.name;
        self.usedDetailView.usedCarDetail = self.usedCarDetail;
        NSArray *array = self.usedCarDetail.piclist;
        NSMutableArray *array2 = [NSMutableArray array];
        for (NSDictionary *dic in array) {
            UIImageView *imageView = [[UIImageView alloc] init];
            NSString *string = dic[@"bigurl"];
            [imageView setImageWithURL:[NSURL URLWithString:string]];
            [array2 addObject:imageView];
        }
        [self.activityView stopAnimating];
        self.carIconScrollView = [[CarIconScrollView alloc] initWithFrame:(CGRectMake(0, 0, kWidth, kHeight / 2.4)) imageArray:array2];
        
        [self.mainScrollView addSubview:self.carIconScrollView];
        self.usedDetailView.hidden = NO;
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"%@",error);
    }];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = kBackGroundColor;
    [self.activityView startAnimating];
    NSLog(@"%@",self.ID);
    if (self.ID != nil) {
        [self jsonUsedCarDetail];
    }
    self.mainScrollView = [[UIScrollView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.mainScrollView.contentSize = CGSizeMake(0, kHeight + kHeight / 10);
    [self.view addSubview:self.mainScrollView];
    self.usedDetailView = [[UsedCarDetailView alloc] initWithFrame:(CGRectMake(0, kHeight / 2.3 ,kWidth, kHeight + kHeight / 10 - kHeight / 2.3))];
    [self.mainScrollView addSubview:self.usedDetailView];
    self.usedDetailView.hidden = YES;
}
- (void)viewWillAppear:(BOOL)animated {
    self.navigationController.navigationBar.translucent = NO;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
